<% all_events = subject_events(profile_or_current_subject, {:scope => scope, :limit => 0, :page=> defined?(page) ? page : 0, :sort_by=> params[:sort_by]||(defined?(sort_by) ? sort_by : "popularity")}) %>
<% all_events.each do |event| %>
    <%= render :partial => 'events/event', :locals => { :event => event } %>
<% end %>

<script>   
  <%if request.xhr?%>
    update_pageless_state("events", <%=all_events.num_pages%>, <%=all_events.current_page%>);
  <%else%>
    document.addEventListener("DOMContentLoaded", function(){  
      update_pageless_state("events", <%=all_events.num_pages%>, <%=all_events.current_page%>);
    });
  <%end%> 
</script>

